﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using Official = Microsoft.International.Converters.PinYinConverter;

namespace WFL.Charset
{
    /// <summary>
    /// 封装了简体中文的读音和笔画等基本信息
    /// （该类仅仅是对微软提供的同名的类的内嵌式封装）
    /// </summary>
    public class ChineseChar
    {
        #region static

        /// <summary>
        /// 检索具有指定笔画数的字符个数
        /// </summary>
        /// <param name="strokeNumber"></param>
        /// <returns></returns>
        public static short GetCharCount(short strokeNumber)
        {
            return Official.ChineseChar.GetCharCount(strokeNumber);
        }

        /// <summary>
        /// 获取给定拼音的所有同音字
        /// </summary>
        /// <param name="pinyin"></param>
        /// <returns></returns>
        public static char[] GetChars(string pinyin)
        {
            return Official.ChineseChar.GetChars(pinyin);
        }

        /// <summary>
        /// 检索具有指定笔画数的所有字符串
        /// </summary>
        /// <param name="strokeNumber"></param>
        /// <returns></returns>
        public static char[] GetChars(short strokeNumber)
        {
            return Official.ChineseChar.GetChars(strokeNumber);
        }

        /// <summary>
        /// 检索具有指定拼音的字符数
        /// </summary>
        /// <param name="pinyin"></param>
        /// <returns></returns>
        public static short GetHomophoneCount(string pinyin)
        {
            return Official.ChineseChar.GetHomophoneCount(pinyin);
        }

        /// <summary>
        /// 检索指定字符的笔画数
        /// </summary>
        /// <param name="ch"></param>
        /// <returns></returns>
        public static short GetStrokeNumber(char ch)
        {
            return Official.ChineseChar.GetStrokeNumber(ch);
        }

        /// <summary>
        /// 识别给出的两个字符是否是同音字
        /// </summary>
        /// <param name="ch1"></param>
        /// <param name="ch2"></param>
        /// <returns></returns>
        public static bool IsHomophone(char ch1, char ch2)
        {
            return Official.ChineseChar.IsHomophone(ch1, ch2);
        }

        /// <summary>
        /// 识别给出的字符串是否是一个有效的汉字字符
        /// </summary>
        /// <param name="ch"></param>
        /// <returns></returns>
        public static bool IsValidChar(char ch)
        {
            return Official.ChineseChar.IsValidChar(ch);
        }

        /// <summary>
        /// 识别给出的拼音是否是一个有效的拼音字符串
        /// </summary>
        /// <param name="pinyin"></param>
        /// <returns></returns>
        public static bool IsValidPinyin(string pinyin)
        {
            return Official.ChineseChar.IsValidPinyin(pinyin);
        }

        /// <summary>
        /// 识别给出的笔画数是否是一个有效的笔画数
        /// </summary>
        /// <param name="strokeNumber"></param>
        /// <returns></returns>
        public static bool IsValidStrokeNumber(short strokeNumber)
        {
            return Official.ChineseChar.IsValidStrokeNumber(strokeNumber);
        }

        #endregion


        private Official.ChineseChar _chnChar;

        /// <summary>
        /// 获取这个汉字字符
        /// </summary>
        public char ChineseCharacter
        {
            get { return _chnChar.ChineseCharacter; }
        }

        /// <summary>
        /// 获取这个字符的拼音个数
        /// </summary>
        public short PinyinCount
        {
            get { return _chnChar.PinyinCount; }
        }

        /// <summary>
        /// 获取这个字符的拼音
        /// </summary>
        public ReadOnlyCollection<string> Pinyins
        {
            get { return _chnChar.Pinyins; }
        }

        /// <summary>
        /// 获取这个字符的笔画数
        /// </summary>
        public short StrokeNumber
        {
            get { return _chnChar.StrokeNumber; }
        }

        /// <summary>
        /// 获取这个字符是否是多音字
        /// </summary>
        public bool IsPolyphone
        {
            get { return _chnChar.IsPolyphone; }
        }

        public ChineseChar(char ch)
        {
            _chnChar = new Official.ChineseChar(ch);
        }

        /// <summary>
        /// 将给出的字符和实例字符的笔画数进行比较
        /// </summary>
        /// <param name="ch"></param>
        /// <returns></returns>
        public int CompareStrokeNumber(char ch)
        {
            return _chnChar.CompareStrokeNumber(ch);
        }

        /// <summary>
        /// 识别字符是否有指定的读音
        /// </summary>
        /// <param name="pinyin"></param>
        /// <returns></returns>
        public bool HasSound(string pinyin)
        {
            return _chnChar.HasSound(pinyin);
        }

        /// <summary>
        /// 识别给出的字符是否是实例字符的同音字
        /// </summary>
        /// <param name="ch"></param>
        /// <returns></returns>
        public bool IsHomophone(char ch)
        {
            return _chnChar.IsHomophone(ch);
        }
    }
}
